using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Zero.Entity.Models.Mapping
{
    public class Sys_MenuMap : EntityTypeConfiguration<Sys_Menu>
    {
        public Sys_MenuMap()
        {
            // Primary Key
            this.HasKey(t => t.MenuID);

            // Properties
            this.Property(t => t.MenuID)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.MenuNo)
                .HasMaxLength(50);

            this.Property(t => t.MenuParentID)
                .HasMaxLength(50);

            this.Property(t => t.MenuName)
                .HasMaxLength(50);

            this.Property(t => t.MenuUrl)
                .HasMaxLength(100);

            this.Property(t => t.MenuIcon)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("Sys_Menu");
            this.Property(t => t.MenuID).HasColumnName("MenuID");
            this.Property(t => t.MenuNo).HasColumnName("MenuNo");
            this.Property(t => t.MenuParentID).HasColumnName("MenuParentID");
            this.Property(t => t.MenuName).HasColumnName("MenuName");
            this.Property(t => t.MenuUrl).HasColumnName("MenuUrl");
            this.Property(t => t.MenuIcon).HasColumnName("MenuIcon");
            this.Property(t => t.IsExternal).HasColumnName("IsExternal");
            this.Property(t => t.IsLeaf).HasColumnName("IsLeaf");
            this.Property(t => t.CreateUserID).HasColumnName("CreateUserID");
            this.Property(t => t.CreateDate).HasColumnName("CreateDate");
            this.Property(t => t.ModifyUserID).HasColumnName("ModifyUserID");
            this.Property(t => t.ModifyDate).HasColumnName("ModifyDate");
            this.Property(t => t.IsEnable).HasColumnName("IsEnable");
            this.Property(t => t.OrderIndex).HasColumnName("OrderIndex");

            this.HasOptional(t => t.Parent)
                .WithMany(t => t.ChildMenus)
                .HasForeignKey(t => t.MenuParentID);
        }
    }
}
